package ch01;

import java.lang.reflect.Field;

/**
 * @author Jane
 * @date 2024-03-15 16:08
 * 通过属性给stuName赋值
 */

public class TestStuFileds {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class c1 = new Student().getClass();
        //实例化对象
        Object zs = c1.newInstance();
        //获取属性
        Field stuName = c1.getDeclaredField("stuName");
        stuName.setAccessible(true);
        stuName.set(zs,"张三");

        Object zs_name = stuName.get(zs);
        System.out.println(zs_name);

    }
}
